<template>
  <div v-show="$route.name === 'material-allocation-detail'">
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/apply-list' }" v-if="come === 'apply-list'">申请记录</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/applied-list' }" v-else-if="come === 'applied-list'">已审批记录</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/material-allocation-list' }" v-else>调拨物资记录</el-breadcrumb-item>
      <el-breadcrumb-item>调拨物资详情</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域--订单数据修改 -->
    <el-card>
      <div style="margin-bottom: 20px;">调拨物资详情</div>
      <el-form>
        <el-row>
          <el-col :span="6">
            <el-form-item label="调拨时间">
              <el-date-picker type="date" placeholder="选择日期" v-model="allocation.allocation_time" readonly></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="申请门店">
              <el-input v-model="allocation.base_to_name" style="width:200px;margin-left: 10px;" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="调拨门店">
              <el-input v-model="allocation.base_from_name" style="width:200px;margin-left: 10px;" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="调拨编号">
              <el-input v-model="allocation.apply_number" style="width:200px;margin-left: 10px;" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
        border
        v-loading="loading"
        :data="allocation.detail"
        style="margin-top: 10px;">
        <el-table-column type="index" width="60" align="center"></el-table-column>
        <el-table-column label="分类" prop="category_name" min-width="130" align="center"></el-table-column>
        <el-table-column label="商品" prop="name" min-width="130" align="center"></el-table-column>
        <el-table-column label="调拨数量" min-width="80" align="center">
          <template slot-scope="scope">
            <span>{{ parseFloat(scope.row.count).toFixed(2) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="comment" min-width="180" align="center"></el-table-column>
      </el-table>
      <el-row v-if="allocation.status === 4">
        <el-alert 
          title="驳回信息"
          type="warning"
          :description="allocation.comment"
          show-icon
          style="margin-top: 10px;">
        </el-alert>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-button  @click="back" style="margin-top: 10px;">返回</el-button>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      loading: false,
      allocate_id: '',
      allocation: [],
      come: ''
    }
  },
  mounted() {
    this.getAllocateData()
  },
  methods: {
    getAllocateData() {
      if (this.$route.params.allocate_id) {
        this.allocate_id = this.$route.params.allocate_id
        this.come = this.$route.params.come
        localStorage.setItem('allocateId', this.$route.params.allocate_id)
      } else {
        this.allocate_id = localStorage.getItem('allocateId')
      }
      if (this.allocate_id) {
        this.getAllocateDetail(this.allocate_id)
      }
    },
    async getAllocateDetail(allocate_id) {
      this.loading = true
      const { data: result } = await this.$http.get('/allocation/' + allocate_id)
      if (result.status !== 200) {
        this.loading = false
        return this.$message.error(result.msg)
      }
      this.loading = false
      this.allocation = result.data
    },
    back () {
      localStorage.removeItem('allocateId')
      this.$router.push({ 
        'name': this.come, 
        'params': { tab: 'third' } 
      })
    }
  }
}
</script>